function a(e) {
    wx.request({
        url: n.globalData.host + "/lotto/v2/join",
        data: {
            lid: e.data.fillId,
            access_token: o.getToken(),
            join: 1,
            join_token: e.data.token,
            name: e.data.username,
            phone: e.data.phone,
            address: e.data.address,
            message: e.data.message
        },
        method: "POST",
        dataType: "json",
        success: function(t) {
            o.hideLoading(), -500 != t.data.sta ? 0 == t.data.sta ? (o.setStorage("winner_info_back", 1), 
            wx.navigateBack({
                delta: 1
            })) : o.showFailedToast("参与抽奖失败，", t.data.msg) : o.login(function() {
                a(e), e.setData({
                    hasUserInfo: !0
                });
            }, function() {
                e.setData({
                    hasUserInfo: !1
                });
            });
        },
        fail: function(a) {
            o.hideLoading(), o.showFailedToast("网络请求超时，", a.errMsg);
        }
    });
}

function e(a) {
    wx.request({
        url: n.globalData.host + "/lotto/v1/winner_info",
        method: "GET",
        data: {
            access_token: o.getToken(),
            lid: a.data.lid
        },
        success: function(t) {
            if (o.hideLoading(), -500 != t.data.sta) if (0 == t.data.sta) {
                var n = t.data.data;
                if ("" == n.name) return void s(a);
                var i = o.getStorage("userInfo").nickName;
                a.setData({
                    username: n.name || i,
                    phone: n.phone,
                    address: n.address,
                    message: n.message,
                    defaultUsername: n.name || i,
                    defaultPhone: n.phone,
                    defaultAddress: n.address,
                    defaultMessage: n.message
                });
            } else "" == a.data.fillId && o.showFailedToast("获取数据失败", t.data.msg); else o.login(function() {
                e(a);
            });
        },
        fail: function(a) {
            o.hideLoading(), o.showFailedToast("获取数据失败", a.errMsg);
        }
    });
}

function t(a) {
    o.showLoading("正在提交数据"), wx.request({
        url: n.globalData.host + "/lotto/v1/recv_info",
        method: "POST",
        data: {
            access_token: o.getToken(),
            lid: a.data.lid,
            name: a.data.username,
            phone: a.data.phone,
            address: a.data.address,
            email: a.data.email,
            post_code: a.data.post,
            message: a.data.message
        },
        success: function(e) {
            if (o.hideLoading(), -500 != e.data.sta) if (0 == e.data.sta) {
                var s = o.getStorage("userInfo"), n = s.nickName, i = s.avatarUrl;
                o.setStorage("userInfo", {
                    nickName: n,
                    avatarUrl: i,
                    phone: a.data.phone
                }), wx.showToast({
                    title: "信息录入成功",
                    icon: "success",
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1500);
                    }
                });
            } else o.showFailedToast("保存数据失败", e.data.msg); else o.login(function() {
                t(a);
            });
        },
        fail: function(a) {
            o.hideLoading(), o.showFailedToast("保存数据失败", a.errMsg);
        }
    });
}

function s(a) {
    o.showLoading("正在获取数据"), wx.request({
        url: n.globalData.host + "/lotto/v1/client_info",
        data: {
            access_token: wx.getStorageSync("accessToken")
        },
        method: "GET",
        success: function(e) {
            if (o.hideLoading(), -500 != e.data.sta) if (0 == e.data.sta) {
                var t = e.data.data;
                a.setData({
                    username: t.name,
                    phone: t.phone,
                    address: t.address,
                    message: t.message,
                    email: t.email,
                    post: t.post_code,
                    defaultUsername: t.name,
                    defaultPhone: t.phone,
                    defaultAddress: t.address,
                    defaultMessage: t.message,
                    defaultEmail: t.email,
                    defaultPost: t.post_code
                });
            } else o.showFailedToast("获取数据失败", e.data.msg); else o.login(function() {
                s(a);
            });
        },
        fail: function(a) {
            console.log("获取数据失败"), o.hideLoading(), o.showFailedToast("获取数据失败");
        }
    });
}

var o = require("../../utils/util.js"), n = getApp();

Page({
    data: {
        phone: "",
        defaultPhone: "",
        username: o.getStorage("userInfo").nickName,
        defaultUsername: o.getStorage("userInfo").nickName
    },
    onLoad: function(a) {
        this.setData({
            lid: a.lid || "",
            fillId: a.fill_id || "",
            token: a.token || ""
        }), e(this);
    },
    onShow: function() {},
    getVerifyCode: function(a) {
        function e(e) {
            return a.apply(this, arguments);
        }
        return e.toString = function() {
            return a.toString();
        }, e;
    }(function(a) {
        var e = this.data.phone;
        o.isTextEmpty(e) ? o.showModelTips("请输入手机号") : (this.setData({
            phone: e
        }), getVerifyCode(this));
    }),
    inputName: function(a) {
        this.setData({
            username: a.detail.value
        });
    },
    inputPhone: function(a) {
        this.setData({
            phone: a.detail.value
        });
    },
    inputAddress: function(a) {
        this.setData({
            address: a.detail.value
        });
    },
    inputEmail: function(a) {
        this.setData({
            email: a.detail.value
        });
    },
    inputPost: function(a) {
        this.setData({
            post: a.detail.value
        });
    },
    inputMessage: function(a) {
        this.setData({
            message: a.detail.value
        });
    },
    inputCode: function(a) {
        this.setData({
            code: a.detail.value
        });
    },
    clearCode: function(a) {
        this.setData({
            code: "",
            defaultCode: ""
        });
    },
    lottoData: function(e) {
        o.postFormId(e.detail.formId), this.data.buttonClicked || (o.buttonClicked(this), 
        o.isTextEmpty(this.data.username) ? o.showModelTips("请输入姓名") : o.isTextEmpty(this.data.phone) ? o.showModelTips("请输入手机号") : this.data.fillId ? a(this) : t(this));
    }
});